import numpy as np
import open3d as o3d


pcd = o3d.io.read_point_cloud("../datasets/standford_cloud_data/China dragon.pcd")
point = np.asarray(pcd.points)
N = point.shape[0]
# 点云随机着色
pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0, 1, size=(N, 3)))
# 可视化点云
o3d.visualization.draw_geometries([pcd], window_name="原始点云",
                                  width=1024, height=768,
                                  left=50, top=50)
# 创建八叉树， 树深为9
octree = o3d.geometry.Octree(max_depth=4)
# 从点云中构建八叉树，适当扩展边界0.001m
octree.convert_from_point_cloud(pcd, size_expand=0.001)
# 可视化八叉树
o3d.visualization.draw_geometries([octree], window_name="可视化八叉树",
                                  width=1024, height=768,
                                  left=50, top=50)

